#!/bin/sh

# Copyright(c) 2011 OpenDomo Services SL. Licensed under GPL v3 or later

ISO="$1"
NETWORK="-net nic,model=ne2k_pci,vlan=0 -net user,vlan=0 -redir tcp:8001::80"
FS="storage.ext2"
STORAGE=" -hdb $FS " 
BOOT=" -cdrom $ISO "
PARAMS=" -boot d -m 64 -soundhw sb16,ac97 -localtime"

if test -z "$ISO"; then
	echo "Debe especificar la imagen a ejecutar"
else
	if test -f storage.ext2; then
		echo "Usando archivo '$STORAGE'"
	else
		echo "Creando almacenaje ..."
		dd if=/dev/zero of=$FS count=100000 && mkfs.ext2 -F $FS || exit 1
		echo "Almacenaje creado!"
	fi
	if test -f ./tests/up.sh; then
		if test -f $ISO; then
			qemu $PARAMS $BOOT $NETWORK $STORAGE 
		else
			echo "No se ha encontrado la imagen"
		fi
	else
		echo "File ./tests/up.sh missing. Aborting"
	fi
fi
